Barakus_Core_Controller = Class.extend({
	init: function()
	{
		this.view = null;
		this.model = {};
		this.name = null;
	},
	run: function()
	{
	},
	preLoad: function(name)
	{
		this.name = name;
	},
	onLoad: function() 
	{
		this.view = new Barakus_Core_View();
	},
	end: function()
	{
		this.view.assign('this', this.view);
		this.view.assign('BARAKUS', BARAKUS);
		this.view.show();
	},
	loadModel: function(model)
	{
		var modelFile = 'model/' + model + '.js';
		var className = 'App_' + ucfirst(model) + 'Model';
		try {
			BARAKUS.webInclude(modelFile, true);
		} catch (err) {
			opera.postError(modelFile + ' not found! ' + err.toString());
		}        
		var controller = null;
		if (class_exists(className))
		{
			var modelInstance = null;
			eval('modelInstance = this.model.' + className + ';');
			if (empty(modelInstance))
			{
				eval('modelInstance = this.model.' + model + ' = new ' + className + '()');		
			}
			return modelInstance; 
		}
	},
	redirect: function(url)
	{
		BARAKUS.rawRequest.redirect(url);
	},
	redirectReferer: function()
	{
		var referer = BARAKUS.rawRequest.headers.Referer[0];
		BARAKUS.rawRequest.redirect(referer);
	}
});